using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
using WPFExcelReport.Helpers;
using WPFExcelReport.Controls;
namespace WPFExcelReport
{
    public partial class VABRESERV
    {
        public DataRow Convert2ABRESERV(DataRow dwInput, string ITXDBVERSION, bool IsConvert = false)
        {
            DataSet SResult = new DataSet();
            SResult = QueryABRESERV(dwInput, 0);
            DataRow dwReturn = null;
            if (SResult.Tables[0].Rows.Count > 0)
            {
                dwReturn = SResult.Tables[0].Rows[0];
            }
            else
            {
                dwReturn = SResult.Tables[0].NewRow();
            }
            switch (ITXDBVERSION)
            {
                case "YGR":
                    #region=========
         dwReturn["ABRMANDANT"] = " ".PadRight(2 ); 
         dwReturn["ABRVFAUFKRS"] = " ".PadRight(2 ); 
         dwReturn["ABRVFAUFLFD"] = " ".PadRight(6 ); 
         dwReturn["ABRVFAUFPOS"] = " ".PadRight(3 ); 
         dwReturn["ABRRWKRS"] = " ".PadRight(2 ); 
         dwReturn["ABRRWLFD"] = " ".PadRight(6 ); 
         dwReturn["ABRRWPOS"] = " ".PadRight(4 ); 
         dwReturn["ABRVAUFKRS"] = " ".PadRight(2 ); 
         dwReturn["ABRVAUFLFD"] = " ".PadRight(6 ); 
         dwReturn["ABRVAUFPOS"] = " ".PadRight(3 ); 
         dwReturn["ABRTP"] = " ".PadRight(4 ); 
         dwReturn["ABRFOLGE"] = " ".PadRight(2 ); 
         dwReturn["ABRLO"] = " ".PadRight(2 ); 
         dwReturn["ABRLB"] = " ".PadRight(2 ); 
         dwReturn["ABRKZ"] = " ".PadRight(1 ); 
         dwReturn["ABRLP"] = " ".PadRight(8 ); 
         dwReturn["ABRAUFBKZ"] = " ".PadRight(1 ); 
         dwReturn["ABRGEBNR"] = " ".PadRight(8 ); 
         dwReturn["ABRGEBPOS"] = " ".PadRight(3 ); 
         dwReturn["ABRKUNDNR"] = " ".PadRight(8 ); 
         dwReturn["ABRWERK"] = " ".PadRight(3 ); 
         dwReturn["ABRABT"] = " ".PadRight(3 ); 
         dwReturn["ABRART"] = " ".PadRight(20 ); 
         dwReturn["ABRVAR"] = " ".PadRight(2 ); 
         dwReturn["ABRSTKNR"] = " ".PadRight(12 ); 
         dwReturn["ABRBEM"] = " ".PadRight(15 ); 
         dwReturn["ABRKDPART"] = " ".PadRight(10 ); 
         dwReturn["ABRSTKLG"] = " ".PadRight(0 ); 
         dwReturn["ABRGEW"] = " ".PadRight(0 ); 
         dwReturn["ABRBRT"] = " ".PadRight(0 ); 
         dwReturn["ABRTAX"] = " ".PadRight(2 ); 
         dwReturn["ABRKANTE"] = " ".PadRight(2 ); 
         dwReturn["ABRSPSTA"] = " ".PadRight(2 ); 
         dwReturn["ABRFILLER"] = " ".PadRight(66 ); 
         dwReturn["ABRAENDZL"] = " ".PadRight(0 ); 
         dwReturn["ABRAENDBEN"] = " ".PadRight(8 ); 
         dwReturn["ABRAENDDAT"] = " ".PadRight(0 ); 
         dwReturn["ABRNEUBEN"] = " ".PadRight(8 ); 
         dwReturn["ABRNEUDAT"] = " ".PadRight(0 ); 
                    #endregion
                    break;
                case "JLT":

                    break;
                default:

                    break;
            }
            if (IsConvert)
            {
                foreach (DataColumn cm in dwInput.Table.Columns)
                {
                    if (dwInput[cm.ColumnName].ToString() == "")
                        continue;
                    if (dwReturn.Table.Columns.Contains(cm.ColumnName))
                    {
                        dwReturn[cm.ColumnName] = dwInput[cm.ColumnName];
                    }
                }
            }
            return dwReturn;
        }
        public void MapABRESERV(ref DataRow dwLocal, DataRow dwData)
        {
            BlindMap(ref dwLocal, dwData);
        }
        public void SaveABRESERV(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            setResult = QueryABRESERV(dwData);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }
            MapABRESERV(ref dwLocal, dwData);

            if (!flgExist)
            {

                InsertABRESERV(dwLocal, ITXDBVERSION);
            }
            UpdateABRESERV(dwLocal);
        }
        public void InsertABRESERV(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            switch (ITXDBVERSION)
            {
                case "YGR":
                    or1.CommandText = "INSERT INTO ABRESERV(VAKBMANDANT, VAKBKOLL, VAKBART, VAKBKUNDNR, VAKBFARBE, VAKBKDARTNR, VAKBKDARTBEZ, VAKBKDFARBNR, VAKBANDRUCK, VAKBMEGEW, VAKBMENGEH, VAKBGEWVON, VAKBGEWBIS, VAKBGEWCA, VAKBGEWFKT, VAKBGEWGRP, VAKBMEGFKT, VAKBMEGGRP, VAKBAENDZL, VAKBAENDBEN, VAKBAENDDAT, VAKBNEUBEN, VAKBNEUDAT, VAKBFILLER)"
                        + " VALUES (:VAKBMANDANT, :VAKBKOLL, :VAKBART, :VAKBKUNDNR, :VAKBFARBE, '                         ', '                         ', '                             ', ' ', '   ', '   ', 0, 0, ' ', '000000000000', ' ', '000000000000', ' ', 0, '        ', '000000', '        ', '      ', '                                          ')";
                    or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                //VAFMANDANT VAFKOLL VAFART VAFFARBE VAFBEZ VAFFFARBE

            }
            
            Connect2Proxy(or1);
        }
        public DataSet QueryABRESERV(DataRow dwData, int option = 1)
        {
            DataSet Return;
            DataSet Result = new DataSet();
            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 0:
                    or1.CommandText = "SELECT * FROM ABRESERV WHERE  ROWNUM<2 ";
                    break;
              
                case 99:
                    or1.CommandText = "SELECT * FROM ABRESERV  WHERE ROWNUM<50";
                    break;
                default:
                    break;
            }
            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
                Result.Tables[0].TableName = "ABRESERV";
            Return = Result;
            return Return;
        }
        public void DeleteABRESERV(DataRow dwData, int option = 1)
        {

            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "DELETE FROM ABRESERV   WHERE  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                     or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                default:
                    break;
            }
            Connect2Proxy(or1);
        } 
      
        public void UpdateABRESERV(DataRow dwData, string ITXDBVERSION = "50.24", int option = 1)
        {
            OracleCommand or1;
            DataSet Result = new DataSet();
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    #region====Command==== 
                    or1.CommandText = "UPDATE ABRESERV SET "
                    +"ABRMANDANT= :ABRMANDANT,"
                    +"ABRVFAUFKRS= :ABRVFAUFKRS,"
                    +"ABRVFAUFLFD= :ABRVFAUFLFD,"
                    +"ABRVFAUFPOS= :ABRVFAUFPOS,"
                    +"ABRRWKRS= :ABRRWKRS,"
                    +"ABRRWLFD= :ABRRWLFD,"
                    +"ABRRWPOS= :ABRRWPOS,"
                    +"ABRVAUFKRS= :ABRVAUFKRS,"
                    +"ABRVAUFLFD= :ABRVAUFLFD,"
                    +"ABRVAUFPOS= :ABRVAUFPOS,"
                    +"ABRTP= :ABRTP,"
                    +"ABRFOLGE= :ABRFOLGE,"
                    +"ABRLO= :ABRLO,"
                    +"ABRLB= :ABRLB,"
                    +"ABRKZ= :ABRKZ,"
                    +"ABRLP= :ABRLP,"
                    +"ABRAUFBKZ= :ABRAUFBKZ,"
                    +"ABRGEBNR= :ABRGEBNR,"
                    +"ABRGEBPOS= :ABRGEBPOS,"
                    +"ABRKUNDNR= :ABRKUNDNR,"
                    +"ABRWERK= :ABRWERK,"
                    +"ABRABT= :ABRABT,"
                    +"ABRART= :ABRART,"
                    +"ABRVAR= :ABRVAR,"
                    +"ABRSTKNR= :ABRSTKNR,"
                    +"ABRBEM= :ABRBEM,"
                    +"ABRKDPART= :ABRKDPART,"
                    +"ABRSTKLG= :ABRSTKLG,"
                    +"ABRGEW= :ABRGEW,"
                    +"ABRBRT= :ABRBRT,"
                    +"ABRTAX= :ABRTAX,"
                    +"ABRKANTE= :ABRKANTE,"
                    +"ABRSPSTA= :ABRSPSTA,"
                    +"ABRFILLER= :ABRFILLER,"
                    +"ABRAENDZL= :ABRAENDZL,"
                    +"ABRAENDBEN= :ABRAENDBEN,"
                    +"ABRAENDDAT= :ABRAENDDAT,"
                    +"ABRNEUBEN= :ABRNEUBEN,"
                    +"ABRNEUDAT= :ABRNEUDAT,"
                        + " WHERE  "
                        + "  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                    #endregion

                    #region====Parameters====
          or1.Parameters.Add("ABRMANDANT", OracleType.NVarChar).Value = dwData["ABRMANDANT"].ToString(); 
          or1.Parameters.Add("ABRVFAUFKRS", OracleType.NVarChar).Value = dwData["ABRVFAUFKRS"].ToString(); 
          or1.Parameters.Add("ABRVFAUFLFD", OracleType.NVarChar).Value = dwData["ABRVFAUFLFD"].ToString(); 
          or1.Parameters.Add("ABRVFAUFPOS", OracleType.NVarChar).Value = dwData["ABRVFAUFPOS"].ToString(); 
          or1.Parameters.Add("ABRRWKRS", OracleType.NVarChar).Value = dwData["ABRRWKRS"].ToString(); 
          or1.Parameters.Add("ABRRWLFD", OracleType.NVarChar).Value = dwData["ABRRWLFD"].ToString(); 
          or1.Parameters.Add("ABRRWPOS", OracleType.NVarChar).Value = dwData["ABRRWPOS"].ToString(); 
          or1.Parameters.Add("ABRVAUFKRS", OracleType.NVarChar).Value = dwData["ABRVAUFKRS"].ToString(); 
          or1.Parameters.Add("ABRVAUFLFD", OracleType.NVarChar).Value = dwData["ABRVAUFLFD"].ToString(); 
          or1.Parameters.Add("ABRVAUFPOS", OracleType.NVarChar).Value = dwData["ABRVAUFPOS"].ToString(); 
          or1.Parameters.Add("ABRTP", OracleType.NVarChar).Value = dwData["ABRTP"].ToString(); 
          or1.Parameters.Add("ABRFOLGE", OracleType.NVarChar).Value = dwData["ABRFOLGE"].ToString(); 
          or1.Parameters.Add("ABRLO", OracleType.NVarChar).Value = dwData["ABRLO"].ToString(); 
          or1.Parameters.Add("ABRLB", OracleType.NVarChar).Value = dwData["ABRLB"].ToString(); 
          or1.Parameters.Add("ABRKZ", OracleType.NVarChar).Value = dwData["ABRKZ"].ToString(); 
          or1.Parameters.Add("ABRLP", OracleType.NVarChar).Value = dwData["ABRLP"].ToString(); 
          or1.Parameters.Add("ABRAUFBKZ", OracleType.NVarChar).Value = dwData["ABRAUFBKZ"].ToString(); 
          or1.Parameters.Add("ABRGEBNR", OracleType.NVarChar).Value = dwData["ABRGEBNR"].ToString(); 
          or1.Parameters.Add("ABRGEBPOS", OracleType.NVarChar).Value = dwData["ABRGEBPOS"].ToString(); 
          or1.Parameters.Add("ABRKUNDNR", OracleType.NVarChar).Value = dwData["ABRKUNDNR"].ToString(); 
          or1.Parameters.Add("ABRWERK", OracleType.NVarChar).Value = dwData["ABRWERK"].ToString(); 
          or1.Parameters.Add("ABRABT", OracleType.NVarChar).Value = dwData["ABRABT"].ToString(); 
          or1.Parameters.Add("ABRART", OracleType.NVarChar).Value = dwData["ABRART"].ToString(); 
          or1.Parameters.Add("ABRVAR", OracleType.NVarChar).Value = dwData["ABRVAR"].ToString(); 
          or1.Parameters.Add("ABRSTKNR", OracleType.NVarChar).Value = dwData["ABRSTKNR"].ToString(); 
          or1.Parameters.Add("ABRBEM", OracleType.NVarChar).Value = dwData["ABRBEM"].ToString(); 
          or1.Parameters.Add("ABRKDPART", OracleType.NVarChar).Value = dwData["ABRKDPART"].ToString(); 
          or1.Parameters.Add("ABRSTKLG", OracleType.NVarChar).Value = dwData["ABRSTKLG"].ToString(); 
          or1.Parameters.Add("ABRGEW", OracleType.NVarChar).Value = dwData["ABRGEW"].ToString(); 
          or1.Parameters.Add("ABRBRT", OracleType.NVarChar).Value = dwData["ABRBRT"].ToString(); 
          or1.Parameters.Add("ABRTAX", OracleType.NVarChar).Value = dwData["ABRTAX"].ToString(); 
          or1.Parameters.Add("ABRKANTE", OracleType.NVarChar).Value = dwData["ABRKANTE"].ToString(); 
          or1.Parameters.Add("ABRSPSTA", OracleType.NVarChar).Value = dwData["ABRSPSTA"].ToString(); 
          or1.Parameters.Add("ABRFILLER", OracleType.NVarChar).Value = dwData["ABRFILLER"].ToString(); 
          or1.Parameters.Add("ABRAENDZL", OracleType.NVarChar).Value = dwData["ABRAENDZL"].ToString(); 
          or1.Parameters.Add("ABRAENDBEN", OracleType.NVarChar).Value = dwData["ABRAENDBEN"].ToString(); 
          or1.Parameters.Add("ABRAENDDAT", OracleType.NVarChar).Value = dwData["ABRAENDDAT"].ToString(); 
          or1.Parameters.Add("ABRNEUBEN", OracleType.NVarChar).Value = dwData["ABRNEUBEN"].ToString(); 
          or1.Parameters.Add("ABRNEUDAT", OracleType.NVarChar).Value = dwData["ABRNEUDAT"].ToString(); 
                    #endregion
                    break; 
                default:
                    break;
            }


            Connect2Proxy(or1);
        }
    }
}
